package com.example.administrator.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

public class Main2Activity extends AppCompatActivity {

    private LinearLayout linearLayout;
    private Button button;


    //    private Button btn_1, btn_2,btn_3;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();
        initData();
        initEvent();}
//        btn_1 = (Button) findViewById(R.id.btn_1);
//        btn_2 = (Button) findViewById(R.id.btn_2);
//        btn_3 = (Button) findViewById(R.id.btn_3);
//        btn_3.setOnClickListener(this);
//        btn_1.setOnClickListener(new View.OnClickListener(){
//            public void onClick(View view){
//                btn_1.setText("按钮1已被点击");
//            }
//        });
//    }
//    public void click(View view){
//
//    }


//第一步 创建试图
private void initView(){
    linearLayout = (LinearLayout) findViewById(R.id.linearlayout);
    button = (Button) findViewById(R.id.button);
}
//第二步 获取数据
private void initData(){
}

//第三步 事件监听
private void initEvent() {
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            linearLayout.setBackgroundColor(getResources().getColor(R.color.colorAccent));
        }
    });
}}


